package com.yhsimon.proxy;

/**静态代理
 *
 */
public class StaticProxy {
    public static void main(String[] args) {

//        new Thread(()-> System.out.println("Love You")).start();

//        new WeddingCompany(new You()).happyMarry();


        WeddingCompany weddingCompany=new WeddingCompany(new You());
        weddingCompany.happyMarry();
    }
}
interface Marry{
    void happyMarry();
}

//真实角色：你去结婚
class You implements Marry{
    @Override
    public void happyMarry() {
        System.out.println("YHSimon结婚了");
    }
}

//代理角色：帮助你结婚
class WeddingCompany implements Marry{

    //代理谁？--》真实目标角色
    private Marry target;

    public WeddingCompany(Marry target) {
        this.target = target;
    }

    @Override
    public void happyMarry() {
        before();
        this.target.happyMarry();//真实对象做的事情
        after();
    }

    private void after() {
        System.out.println("结婚之后，收拾现场");
    }

    private void before() {
        System.out.println("结婚之前，布置现场");
    }
}